var appPath = getAppPath();
var EDIT_IMG_IDX = 0;
var EDIT_IMG_IDX_2 = 0;

$(function(){
	// 商品分类
	// 大分类
	$("#queryTypeL").combobox({
		data:[{type_id:0,type_name:'[不限]'},
		      {type_id:4,type_name:'印品'},
		      {type_id:5,type_name:'配件'},
		      {type_id:9,type_name:'虚拟商品'},
		      {type_id:1010,type_name:'Logo商品'},
		      {type_id:1011,type_name:'营销商品'}],
		valueField:'type_id',
		textField:'type_name',
		onSelect:function(selRecdL){
			$("#queryTypeM").combobox("clear");
			$("#queryTypeM").combobox("loadData",{});
			$("#queryTypeS").combobox("clear");
			$("#queryTypeS").combobox("loadData",{});
			
			var topId=selRecdL.type_id;
			// 中分类
			$("#queryTypeM").combobox({
				url:appPath+'/itbTg/getTypeForCombo.action?blkFlg=1&parent='+topId,
				valueField:'type_id',
				textField:'type_name',
				onSelect:function(selRecdM){
					$("#queryTypeS").combobox("clear");
					$("#queryTypeS").combobox("loadData",{});
					
					// 小分类
					var parentId=selRecdM.type_id;
					if(Number(parentId)>0){
						$("#queryTypeS").combobox({
							url:appPath+'/itbTg/getTypeForCombo.action?blkFlg=1&parent='+parentId,
							valueField:'type_id',
							textField:'type_name',
							onSelect:function(selRecdS){
								// TODO
							}
						});
					}
				}
			});
		}
	});
	
	initItemsGrid();
	initTmplGrid();
});

// 商品列表初始化
function initItemsGrid(){
	$('#itemsGrid').datagrid({
	    url:appPath + "/itbItems/getItemsInfoPg.action",
	    height:'full',
	    striped:true,
	    fitColumns:true,
	    nowrap: false,// 换行
	    queryParams: getQueryParam(),
	    singleSelect:false,
	    selectOnCheck:true,
	    checkOnSelect:true,
	    frozenColumns:[[
	        {field:'ck',checkbox:'true',width:10,align:'center',sortable:false}
	    ]],
	    columns:[[
  	        {field:'item_id',title:'商品ID',width:35,align:'center',sortable:false},
  	        {field:'item_no',title:'商品编号',width:50,align:'center',sortable:false},
  	        {field:'item_name',title:'商品名称',width:70,align:'center',sortable:false},
	        {field:'top_type_id',title:'大分类',width:40,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  var ret = '<span style="color:red">未知</span>';
		    			switch(Number(value||'0')){
		    				case 4: ret='<span style="color:red">印品</span>'; break;
		    				case 5: ret='<span style="color:blue">配件</span>'; break;
		    				case 9: ret='<span style="color:green">虚拟商品</span>'; break;
		    				case 1010: ret='<span style="color:green">Logo商品</span>'; break;
		    				case 1011: ret='<span style="color:green">营销商品</span>'; break;
		    			}
		    			return ret;
		    	  }
		      },
	        {field:'type_name',title:'商品分类',width:40,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  return value||'<span style="color:red">未知</span>';
		    	  }
		      },
	        {field:'design_id',title:'关联模版ID',width:45,align:'center',sortable:false,
  	        	formatter:function(value, rowData, rowIndex){
  	        		var topType = Number(rowData.top_type_id||'0');
  	        		if(topType!=4 && topType!=1010 && topType!=1011) {
  	        			return '<span style="color:red">N/A</span>';
  	        		}
  	        		
  	        		var show = '<span style="color:red">未关联</span>';
	        		if(Number(rowData.design_id||'0')>0){
	        			show = value;
	        		}
	        		return "<a href='javascript:void(0)' onClick='editLinkTmpl("+rowData.item_id+","+rowData.type_id+")'>"+show+"</a>";
	        	}
		    },
		    {field:'pp',title:'套餐设定',width:40,align:'center',sortable:false,
  	        	formatter:function(value, rowData, rowIndex){
  	        		 if(!rowData.item_id) return "N/A";
		    		  var ret = "<a href='javascript:void(0)'><img width='12px' height='12px' style='border:0px' src='"+appPath+"/js/lib/jquery-easyui/themes/icons/pencil.png' title='设置' ";
					  ret += " onClick='editPp("+rowData.item_id+","+rowData.top_type_id+")'/></a>";
					  return ret;
	        	}
		    },
	        {field:'detail',title:'商品详情 [点击查看/编辑]',width:90,align:'left',sortable:false,
	        	formatter:function(value, rowData, rowIndex){
	        		if(!rowData.item_id) return "N/A";
	        		var show = '[点击查看]';
	        		if(rowData.desc && rowData.desc.length>0){
	        			if(rowData.desc.length>16){
	        				show = rowData.desc.substr(0,15)+'...';
	        			}else{
	        				show = rowData.desc;
	        			}
	        		}
	        		var re = '';
	        		if (rowData.comImgIdx == 0){
	        			re = '<font color="red">异常下标:'+rowData.comImgIdx+'</font>';
	        		} else {
	        			re = '<font color="green">下标:'+rowData.comImgIdx+'</font>';
	        		}
	        		
	        		return "<a href='javascript:void(0)' onClick='showDetail("+rowData.item_id+")'>"+show+"</a><br/>"+re;
	        	}
		    },
		    {field:'state',title:'状态',width:35,align:'center',sortable:false,
  	        	formatter:function(value, rowData, rowIndex){
	        		if(!rowData.item_id) return "N/A";
	        		return getState4Show(value);
	        	}
		    },
	        {field:'create_time',title:'创建时间',width:45,align:'center',sortable:false},
	        {field:'update_time',title:'更新时间',width:45,align:'center',sortable:false}
	    ]],
	    hideColumn:['user_type'],
	    // view: imgView,// 自定义View
	    pagination:true,
		rownumbers:true,
		toolbar:[
			{
				text:'新建商品',
				iconCls:'icon-add',
				handler:function(){
					addItem();
				}
			},
			{
				text:'上架商品',
				iconCls:'icon-ok',
				handler:function(){
					onSale();
				}
			},
			{
				text:'下架商品',
				iconCls:'icon-cancel',
				handler:function(){
					offShelved();
				}
			},
			{
				text:'删除商品',
				iconCls:'icon-cancel',
				handler:function(){
					delItem();
				}
			}
		]
	});
}

// 关联模版列表初始化
function initTmplGrid(){
	$('#tmplGrid').datagrid({
	    url:appPath + "/itbDesign/getDesignInfoLst.action",
	    height:'360',
	    striped:true,
	    fitColumns:true,
	    queryParams: getQueryParam2(),
	    singleSelect:true,
	    selectOnCheck:true,
	    checkOnSelect:true,
	    frozenColumns:[[
	        {field:'ck',checkbox:'true',width:10,align:'center',sortable:false}
	    ]],
	    columns:[[
  	        {field:'thumb',title:'缩略图',width:70,align:'center',sortable:false,
	        	formatter:function(thumb, rowData, rowIndex){
	        		var retUrl = '';
	        		if (rowData.thumb) {
	        			retUrl = '<a href="' + rowData.thumb + '" target="_blank">'
	        				+ '<div style="display:table;text-align:center;height:120px;width:100%">'
	        				+ '<span style="display:table-cell;vertical-align:middle">'
	        				+ '<img src="' + rowData.thumb.replace('oss-cn-hangzhou.aliyuncs.com','img-cn-hangzhou.aliyuncs.com') + '@110h_128w_1l.png'
	        				+ '" style="display:inline;max-height:110px;max-width:128px"></span></div></a>';
	        		}
	        		return retUrl;
	        	}},
	        {field:'design_id',title:'设计ID',width:35,align:'left',sortable:false},
	        {field:'map_id',title:'分页ID',width:35,align:'left',sortable:false,
		    	  formatter:function(mapId, rowData, rowIndex){
		    		  return '<span style="color:red">'+mapId+'</span>';
		    	  }
		      },
	        {field:'size',title:'尺寸',width:60,align:'left',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  return 'W('+(rowData.width||'N/A')+')*H('+(rowData.height||'N/A')+')';
		    	  }
		      },
		    {field:'top_type',title:'主分类',width:40,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  var tn = '<span style="color:red">未知</span>';
		    		  switch(Number(value||'0')){
		    		  	case 1: tn='单页';break;
		    		  	case 2: tn='多页';break;
		    		  	case 3: tn='PPT';break;
		    		  	case 4: tn='<span style="color:red">印品</span>';break;
		    		  	case 6: tn='社交媒体';break;
		    		  	case 7: tn='电商';break;
		    		  	case 8: tn='微商';break;
		    		  	case 1010: tn='Logo商品';break;
		    		  	case 1011: tn='营销商品';break;
		    		  }
		    		  return tn;
		    	  }
		      },
	        {field:'editType',title:'子分类',width:40,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  return rowData.type_name || '<span style="color:red">未分类</span>';
		    	  }
		      },
	        {field:'design_name',title:'设计模版名称',width:80,align:'left',sortable:false},
        	{field:'state',title:'模版状态',width:40,align:'center',sortable:false,
	        	formatter:function(state, rowData, rowIndex){
	        		var s = Number(state||'0');
	        		var nm = '未知';
	        		switch(s){
	        			case 10: nm='制作中';break;
	        			case 20: nm='待审核';break;
	        			case 31: nm='初审OK';break;
	        			case 41: nm='初审NG';break;
	        			case 32: nm='复审OK';break;
	        			case 42: nm='复审NG';break;
	        		}
	        		return nm;
	        	}},
	        {field:'publish',title:'发布状态',width:40,align:'center',sortable:false,
	        	formatter:function(publish, rowData, rowIndex){
	        		if (Number(publish) == 1) return '<span style="color:red">已发布</span>';
	        		return '<span style="color:green">未发布</span>';
	        	}},
	        {field:'create_time',title:'创建时间',width:40,align:'center',sortable:false},
	        {field:'update_time',title:'更新时间',width:40,align:'center',sortable:false}
	    ]],
	    hideColumn:['user_type'],
	    pagination:true,
		rownumbers:true,
		toolbar:[]
	    
	});
}

function getState4Show(value){
	var state = '<span style="color:red">未知</span>';
	switch(Number(value||'0')){
		case 10: state='<span style="color:blue">编辑中</span>'; break;
		case 20: state='<span style="color:green">上架</span>'; break;
		case 30: state='<span style="color:red">下架</span>'; break;
	}
	return state;
}

//// 商品详细配图
//function initUploader(){
//	//var url = "http://upload.itbour.com/upload/user?device=101&user_type=0&user_id="+(g_userId||0);// 写DB
//	var url = "http://upload.itbour.com/upload/?device=101&user_type=0&user_id="+(g_userId||0);// 不写DB
//	var option = {};
//    option.id = 'selImgFile';
//    option.url = url;
//    option.callback = function(res){
//    	if(!res.success){
//    		alert(res.msg);
//            return;
//    	}
//    	if(res && res.data && res.data.url && res.data.url.length>0){
//    		EDIT_IMG_IDX = Number(EDIT_IMG_IDX||0)+1;
//    		console.info("全局"+EDIT_IMG_IDX);
//    		$("#imgIdx").val(EDIT_IMG_IDX);
//    		var showImg = res.data.url+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
//			var imgHtml = '<div style="margin:20px;margin-top:30px;" id="editImg_'+EDIT_IMG_IDX+'">'+
//				'<a href="' + res.data.url + '" target="_blank" id="editImg_a_'+EDIT_IMG_IDX+'" class="editImgUrl" style="margin-right:10px;">'+
//				'<img id="editImg_a_img_'+EDIT_IMG_IDX+'" src="'+showImg+'" style="display:inline;">'+
//				'</a>'+
//				'<a href="javascript:void(0)" onclick="delEditImg('+EDIT_IMG_IDX+')">删除</a>'+
//				'<a href="javascript:void(0)" style="margin-left:20px;" onclick="upImage('+EDIT_IMG_IDX+')"">上移</a>'+
//				'</div>';
//			$("#editItemThumb").append(imgHtml);
//    	}
//    }
//    option.imgExts = ['jpg','jpeg','png'];
//    var uploader = new AjaxUploadEx(option);
//}

//移除副图图片
function delEditImg(idx){
	var comImgIdx=EDIT_IMG_IDX;
	$("#editImg_"+idx).remove();
	var arrImgUrl=[];
	var arr=$("a.editImgUrl");
	for (var i = 0; i < arr.length; i++) {
		var imgUrl = $(arr[i]).attr('href');
		if(imgUrl&&imgUrl.length>0){
			arrImgUrl.push(imgUrl);
		}
	}
	$('#editItemThumb').html('');
	if(comImgIdx>=0){
		comImgIdx=comImgIdx-1;
	}
	doSort(arrImgUrl,comImgIdx);
}

//向上移动图片
function upImage(idx){
	var tmp=$("#editImg_"+(idx-1));
	if(tmp!=null&&tmp.length>0){
		var a = $("#editImg_a_"+idx).attr('href'); 
		var b = $("#editImg_a_"+(idx-1)).attr('href'); 
		$("#editImg_a_"+(idx-1)+"").attr('href',a);
		$("#editImg_a_"+idx+"").attr('href',b);
		var ai = $("#editImg_a_img_"+idx).attr('src'); 
		var bi = $("#editImg_a_img_"+(idx-1)).attr('src'); 
		$("#editImg_a_img_"+(idx-1)+"").attr('src',ai);
		$("#editImg_a_img_"+idx+"").attr('src',bi);
	} else {
		$.messager.alert('提示信息','图片在第一张不用上移','warning');
	}
}

//// 商品主题配图
//function initUploader2(imgUrl){
////	var imgUrl = 'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/04/20/124622380_v8PKbpprJzyD8zUEZ5iH.jpg';
//	if(imgUrl){
//		delEditImg2(EDIT_IMG_IDX_2);// 只能有一张主图
//		var showImg = imgUrl+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
//		var imgHtml = '<div style="margin:20px;margin-top:30px;" id="editImg2_'+EDIT_IMG_IDX_2+'">'+
//			'<a href="' + imgUrl + '" target="_blank" class="editImgUrl2" style="margin-right:10px;">'+
//			'<img src="'+showImg+'" style="display:inline;">'+
//			'</a>'+
//			'<a href="javascript:void(0)" onclick="delEditImg2('+EDIT_IMG_IDX_2+')"">删除</a>'
//			'</div>';
//		$("#editItemThumb2").append(imgHtml);
//	}
//}
function delEditImg2(idx){
	$("#editImg2_"+idx).remove();
}

// 新建商品
function addItem(){
	$("#editTable").show();
	$('#editForm').form('clear');
	$('#editItemThumb2').html('');
	$('#editItemThumb').html('');
	$("#editItemId").val('');
	$('#editComImg').html('');
	
	$("#editTypeL").combobox('enable');
	$("#editTypeM").combobox('enable');
	$("#editTypeS").combobox('enable');
	
	// 大分类
	$("#editTypeL").combobox({
		data:[{type_id:4,type_name:'印品'},
		      {type_id:5,type_name:'配件'},
		      {type_id:9,type_name:'虚拟商品'},
		      {type_id:1010,type_name:'Logo商品'},
		      {type_id:1011,type_name:'营销商品'}],
		valueField:'type_id',
		textField:'type_name',
		onSelect:function(selRecdL){
			var topTypeId=selRecdL.type_id;
			
			// 中分类
			$("#editTypeM").combobox({
				url:appPath+'/itbTg/getTypeForCombo.action?blkFlg=0&parent='+topTypeId,
				valueField:'type_id',
				textField:'type_name',
				onSelect:function(selRecdM){
					$("#editTypeS").combobox("clear");
					$("#editTypeS").combobox("loadData",{});
					
					// 小分类
					var parentId=selRecdM.type_id;
					if(Number(parentId)>0){
						$("#editTypeS").combobox({
							url:appPath+'/itbTg/getTypeForCombo.action?blkFlg=0&parent='+parentId,
							valueField:'type_id',
							textField:'type_name',
							onLoadSuccess:function(){
								var dataS = $('#editTypeS').combobox('getData');
								if(dataS && dataS.length>0){
									$("#editTypeS").combobox('select',dataS[0].type_id).combobox('enable');
								}
							}
						});
					}
				},
				onLoadSuccess:function(){
					var dataM = $('#editTypeM').combobox('getData');
					if(dataM && dataM.length>0){
						$("#editTypeM").combobox('select',dataM[0].type_id).combobox('enable');
					}
				}
			});
		},
		onLoadSuccess:function(){
			var dataL = $('#editTypeL').combobox('getData');
			if(dataL && dataL.length>0){
				$("#editTypeL").combobox('select',dataL[0].type_id).combobox('enable');
			}
		}
	});	
	
	$("#editBtn").show();
	$('#editDlg').window({
		title:'新建商品',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	initOSS();
	initOSS1();
	
	$('#editDlg').window('move',{top:20,left:20});
	$('#editDlg').window('open');
}

// 编辑商品信息
function doEdit(){
	var itemId = $("#editItemId").val();
	var typeS = $("#editTypeS").combobox('getValue');
	var itemNo = $("#editItemNo").val();
	var itemNm = $('#editItemName').val();
	var desc = $("#editDesc").val();
	var imgIdx=$("#imgIdx").val();
	//保存配图数据
	var arrImgUrl = [];
	var arr = $("a.editImgUrl");
	 for(var i=0; i<arr.length; i++){
		var imgUrl = $(arr[i]).attr('href');
		if(imgUrl && imgUrl.length>0){
			arrImgUrl.push(imgUrl);
		}
	}
	//获取公共图片信息--加在附图后面
	var comImgArr=$("a.editComImgUrl");
	if(comImgArr.length>0){
		for (var i = 0; i < comImgArr.length; i++) {
			var cImgUrl=$(comImgArr[i]).attr('href');
			if(cImgUrl&&cImgUrl.length>0){
				arrImgUrl.push(cImgUrl);
			}
		}
	}else{
		imgIdx=-1;
	}
	
	// 主图
	var themeImgUrl = '';
	var img2 = $("a.editImgUrl2");
	if(img2) {
		themeImgUrl = img2.attr('href');
	}
	
	if(typeS && Number(typeS||'0')>0) {
		if(itemNo && itemNo.length>0 
			&& itemNm && itemNm.length>0
			&& desc && desc.length>0) {
			// 默认新建
			var url = appPath+"/itbItemsWeb/addItem.action";
			if(Number(itemId||'0')>0) {
				// 更新
				url = appPath+"/itbItemsWeb/updItem.action";
			}
			var sendData = {
				"itemInfo.item_id": itemId||"",
				"itemInfo.type_id": typeS,
				"itemInfo.item_no": itemNo,
				"itemInfo.item_name": itemNm,
				"itemInfo.desc": desc || "",
				"itemInfo.theme_thumb": themeImgUrl||'',
				"itemInfo.thumbs": JSON.stringify(arrImgUrl),
				"itemInfo.comImgIdx":imgIdx||""
			};
		    $.post(url, sendData, function(data){  
				if (data == "ok") { 
					$.messager.alert('提示信息','提交成功','info');
					$('#editDlg').window('close');
					doQuery();
		        } else {
		        	$.messager.alert('提示信息','提交失败','info');
		        }
		    });
			
		} else {
			$.messager.alert('提示信息','请填写商品编码／名称／简介','info');
		}
	    
	}else{
		$.messager.alert('提示信息','请选择商品分类','info');
	}
}

function cancelEdit(){
	$('#editDlg').window('close');
	if (uploader) {
		uploader.destroy();
		uploader = null;
	}
	if (uploader1) {
		uploader1.destroy();
		uploader1 = null;
	}
}

// 查看/更新商品信息
function showDetail(id){
	$("#editTable").show();
	$('#editForm').form('clear');
	$('#editItemThumb2').html('');
	$('#editItemThumb').html('');
	$('#editComImg').html('');
	$("#editItemId").val(id);
	
	$("#editTypeL").combobox('disable');
	$("#editTypeM").combobox('disable');
	$("#editTypeS").combobox('disable');
	
	// 加载数据
	var url = appPath + "/itbItems/getItemsInfoLst.action?item_id="+ id;
	$.get(url,function(ret){
		if (ret && ret.length>0){
			var info = ret[0];
			$("#editItemNo").val(info.item_no||'');
			$("#editItemName").val(info.item_name||'');
			$("#editDesc").val(info.desc||'');
			
			// 大分类
			$("#editTypeL").combobox({
				data:[
				      {type_id:4,type_name:'印品'},
				      {type_id:5,type_name:'配件'},
				      {type_id:9,type_name:'虚拟商品'},
				      {type_id:1010,type_name:'Logo商品'},
				      {type_id:1011,type_name:'营销商品'}
			      ],
				valueField:'type_id',
				textField:'type_name',
				onSelect:function(selRecdL){
					$("#editTypeM").combobox("clear");
					$("#editTypeM").combobox("loadData",{});
					var topTypeId=selRecdL.type_id;
					// 中分类
					$("#editTypeM").combobox({
						url:appPath+'/itbTg/getTypeForCombo.action?blkFlg=0&parent='+topTypeId,
						valueField:'type_id',
						textField:'type_name',
						onSelect:function(selRecdM){
							$("#editTypeS").combobox("clear");
							$("#editTypeS").combobox("loadData",{});
							var parentId=selRecdM.type_id;
							
							// 小分类
							if(Number(parentId)>0){
								$("#editTypeS").combobox({
									url:appPath+'/itbTg/getTypeForCombo.action?blkFlg=0&parent='+parentId,
									valueField:'type_id',
									textField:'type_name',
									onLoadSuccess:function(){
										$("#editTypeS").combobox("select", info.type_id).combobox('disable');
									}
								});
							}
						},
						onLoadSuccess:function(){
							$("#editTypeM").combobox("select", info.parent_type_id).combobox('disable');
						}
					});
				},
				onLoadSuccess:function(){
					$("#editTypeL").combobox("select", info.top_type_id).combobox('disable');
				}
			});
			
			// 主图
			var themeImg = info.theme_thumb;
			if(themeImg && themeImg.length>0) {//?x-oss-process=image/resize,m_lfit,h_100,w_100
				var showImg = themeImg+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
				var imgHtml = '<div style="margin:20px;margin-top:30px;" id="editImg2_'+EDIT_IMG_IDX_2+'">'+
					'<a href="' + themeImg + '" target="_blank" class="editImgUrl2" style="margin-right:10px;">'+
					'<img src="'+showImg+'" style="display:inline;">'+
					'</a>'+
					'<a href="javascript:void(0)" onclick="delEditImg2('+EDIT_IMG_IDX_2+')"">删除</a>'
					'</div>';
				$("#editItemThumb2").append(imgHtml);
			}
			// 配图缩略图
			var comImgIdx=info.comImgIdx;
			var arrImg = JSON.parse(info.thumbs||'[]');
			doSort(arrImg,comImgIdx);//显示附图
			doComImg(arrImg,comImgIdx);//显示通用图片
		}
	});
	
	$("#editBtn").show();
	$('#editDlg').window({
		title:'商品详情/编辑',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	initOSS();
	initOSS1();
	$('#editDlg').window('move',{top:20,left:20});
	$('#editDlg').window('open');
}


//显示通用图片
function doComImg(arrImg,comImgIdx){
	if(comImgIdx>=0){
		for (comImgIdx; comImgIdx < arrImg.length; comImgIdx++) {
			if(arrImg[comImgIdx] && arrImg[comImgIdx].length>0) {
				var showImg = arrImg[comImgIdx]+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
				var imgHtml = '<div style="margin:20px;margin-top:30px;" id="editComImgUrl_'+comImgIdx+'">'+
				'<a href="' +arrImg[comImgIdx] + '" target="_blank" id="editComImgUrl'+comImgIdx+'" class="editComImgUrl" style="margin-right:10px;">'+
				'<img id="comImg_a_img_'+comImgIdx+'" src="'+showImg+'" style="display:inline;">'+
				'</a>'+
				'<a href="javascript:void(0)" onclick="delComImg('+comImgIdx+')"">删除</a>'+
				'</div>';
				$("#editComImg").append(imgHtml);
			}
		}
   }
}

/**
 *删除通用图片 
 */
 function delComImg(idx){
	$("#editComImgUrl_"+idx).remove();
 }

/**
 * 附图展示
 * @param arrImg 	附图图片集合
 * @param comImgIdx	通用图片的起始位置
 */
function doSort(arrImg,comImgIdx){
	EDIT_IMG_IDX=0;
	$("#imgIdx").val(comImgIdx);
	if(comImgIdx>0){
		for(var i=0; i<comImgIdx; i++){
			if(arrImg[i] && arrImg[i].length>0) {
				EDIT_IMG_IDX = Number(EDIT_IMG_IDX||0)+1;// 表示图片的位置// EDIT_IMG_IDX=0初始值 
	    		var showImg = arrImg[i]+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
				var imgHtml = '<div style="margin:20px;margin-top:30px;" id="editImg_'+EDIT_IMG_IDX+'">'+
					'<a href="' +arrImg[i] + '" target="_blank" id="editImg_a_'+EDIT_IMG_IDX+'" class="editImgUrl" style="margin-right:10px;">'+
					'<img id="editImg_a_img_'+EDIT_IMG_IDX+'" src="'+showImg+'" style="display:inline;">'+
					'</a>'+
					'<a href="javascript:void(0)" onclick="delEditImg('+EDIT_IMG_IDX+')"">删除</a>'+
					'<a href="javascript:void(0)" onclick="upImage('+EDIT_IMG_IDX+')" style="margin-left:20px;text-decoration:none;">上移</a>'+
					'</div>';
				$("#editItemThumb").append(imgHtml);
			}
		}
	} else if(comImgIdx==(-1)){
		for(var i=0; i<arrImg.length; i++){
			if(arrImg[i] && arrImg[i].length>0) {
				EDIT_IMG_IDX = Number(EDIT_IMG_IDX||0)+1;// 表示图片的位置// EDIT_IMG_IDX=0初始值
	    		var showImg = arrImg[i]+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
				var imgHtml = '<div style="margin:20px;margin-top:30px;;" id="editImg_'+EDIT_IMG_IDX+'">'+
					'<a href="' +arrImg[i] + '" target="_blank" id="editImg_a_'+EDIT_IMG_IDX+'" class="editImgUrl" style="margin-right:10px;">'+
					'<img id="editImg_a_img_'+EDIT_IMG_IDX+'" src="'+showImg+'" style="display:inline;">'+
					'</a>'+
					'<a href="javascript:void(0)" onclick="delEditImg('+EDIT_IMG_IDX+')"">删除</a>'+
					'<a href="javascript:void(0)" onclick="upImage('+EDIT_IMG_IDX+')" style="margin-left:20px;text-decoration:none;">上移</a>'+
					'</div>';
				$("#editItemThumb").append(imgHtml);
			}
		}
	}
}

// 上架
function onSale(){
	var selectItem=$("#itemsGrid").datagrid("getChecked");
	if(!selectItem || selectItem.length == 0){
		$.messager.alert('提示信息','请选择商品！','warning');
		return;
	}
	for(var i=0; i<selectItem.length; i++){
		if(Number(selectItem[i].top_type_id||'0')==4 && Number(selectItem[i].design_id||'0')<=0){
			$.messager.alert('提示信息','商品未关联模版！','warning');
			return;
		}
	}
	
	$.messager.confirm("确认", "是否确认[上架]所选商品？",
		function(r){
	        if (r) { 
				var ids = "";
				$.each(selectItem, function(index, item){
					ids = ids + item.item_id + ",";
				});
				var sendData = {
					"itemInfo.ids":ids,
					"itemInfo.state":20
				}
				var url = appPath+"/itbItemsWeb/updItem.action";
				$.post(url,sendData,function(data){
					if(data=="ok"){
						$.messager.alert('提示信息','上架成功','info');
						doQuery();
					}else{
						$.messager.alert('提示信息','上架失败','info');
					}
				});
	        }
		}
	);
}
// 下架
function offShelved(){
	var selectItem=$("#itemsGrid").datagrid("getChecked");
	if(!selectItem || selectItem.length == 0){
		$.messager.alert('提示信息','请选择商品！','warning');
		return;
	}
	for(var i=0; i<selectItem.length; i++){
		if(Number(selectItem[i].state||'0')!=20){
			$.messager.alert('提示信息','只能下架[已上架]商品！','warning');
			return;
		}
	}
	
	$.messager.confirm("确认", "是否确认[下架]所选商品？",
		function(r){
	        if (r) { 
				var ids = "";
				$.each(selectItem, function(index, item){
					ids = ids + item.item_id + ",";
				});
				var sendData = {
					"itemInfo.ids":ids,
					"itemInfo.state":30
				}
				var url = appPath+"/itbItemsWeb/updItem.action";
				$.post(url,sendData,function(data){
					if(data=="ok"){
						$.messager.alert('提示信息','下架成功','info');
						doQuery();
					}else{
						$.messager.alert('提示信息','下架失败','info');
					}
				});
	        }
		}
	);
}

// 打开关联模版窗口
function editLinkTmpl(id,typeS){
	$("#tmplTable").show();
	$('#tmplForm').form('clear');
	$("#lnkItemNo").html('');
	$("#lnkItemId").val(id);
	$("#lnkTypeS").val(typeS);
	
	var url = appPath + "/itbItems/getItemsInfoLst.action?item_id="+ id;
	$.get(url,function(ret){
		if (ret && ret.length>0){
			var info = ret[0];
			$("#lnkItemNo").html(info.item_no||'');
		}
	});
	
	$("#tmplGrid").datagrid('unselectAll');
	$("#tmplGrid").datagrid('load', getQueryParam2());
	
	$("#tmplBtn").show();
	$('#tmplDlg').window({
		title:'关联模版设定',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	
	$('#tmplDlg').window('move',{top:20,left:20});
	$('#tmplDlg').window('open');
}

// 关联模版
function doUpdTmpl(){
	var id = $("#lnkItemId").val();
	
	var selectItem=$("#tmplGrid").datagrid("getChecked");
	if(!selectItem || selectItem.length == 0){
		$.messager.alert('提示信息','请选择设计模版！','warning');
		return;
	}
	for(var i=0; i<selectItem.length; i++){
		if(Number(selectItem[i].publish||'0')!=1){
			$.messager.alert('提示信息','不能关联[未发布]模版！','warning');
			return;
		}
	}
	
	$.messager.confirm("确认", "是否确认[关联]所选设计模版？",
		function(r){
	        if (r) { 
	        	var designId = "";
				$.each(selectItem, function(index, item){
					if(Number(item.design_id||'0')>0){
						designId = item.design_id;
						return false;
					}
				});
				var sendData = {
					"itemInfo.item_id":id,
					"itemInfo.design_id":designId
				}
				var url = appPath+"/itbItemsWeb/updItem.action";
				$.post(url,sendData,function(data){
					if(data=="ok"){
						// 反向更新design的关联信息
						var sendData2 = {
							"designId":designId,
							"itemIdForItems":id
						}
						var url2 = appPath+"/itbDesignWeb/updDesignItem.action";
						$.post(url2,sendData2,function(data2){
							if(data2=="ok"){
								$.messager.alert('提示信息','关联模版成功','info');
							} else {
								$.messager.alert('提示信息','但更新设计模版失败','info');
							}
							doQuery();
						});
						
					}else{
						$.messager.alert('提示信息','关联模版失败','info');
					}
				});
	        }
		}
	);
}
// 清除关联
function removeUpdTmpl(){
	var id = $("#lnkItemId").val();
	
	$.messager.confirm("确认", "是否确认[清除]关联的设计模版？",
		function(r){
	        if (r) {
				var url = appPath+"/itbItemsWeb/clrRelDesign.action?itemId="+id;
				$.post(url,function(data){
					if(data=="ok"){
						$.messager.alert('提示信息','清除关联模版成功','info');
						doQuery();
						
					}else{
						$.messager.alert('提示信息','清除关联模版失败','info');
					}
				});
	        }
		}
	);
}
function cancelUpdTmpl(){
	$('#tmplDlg').window('close');
}

// 删除商品
function delItem(){
	var selectItem=$("#itemsGrid").datagrid("getChecked");
	if(!selectItem || selectItem.length == 0){
		$.messager.alert('提示信息','请选择商品！','warning');
		return;
	}
	for(var i=0; i<selectItem.length; i++){
		if(Number(selectItem[i].state||'0')==20){
			$.messager.alert('提示信息','不能删除[已上架]商品！','warning');
			return;
		}
	}
	
	$.messager.confirm("确认", "是否确认[删除]所选商品？",
		function(r){
	        if (r) { 
				var ids = "";
				$.each(selectItem, function(index, item){
					ids = ids + item.item_id + ",";
				});
				var url = appPath+"/itbItemsWeb/delItem.action?ids="+ids;
				$.post(url,function(data){
					if(data=="ok"){
						$.messager.alert('提示信息','删除成功','info');
						doQuery();
					}else{
						$.messager.alert('提示信息','删除失败','info');
					}
				});
	        }
		}
	);
}

// 关联输出参数
function editPp(id,topType){
	$("#ppItemId").val(id);
	$('#ppContent').html('');
	
	var url = appPath+"/itbItems/getPpInfoLst.action?itemId="+id;
	if(Number(topType||'0')==1010) {
		url += '&ppType=10';// logo商品
	} else if(Number(topType||'0')==1011) {
		url += '&ppType=11';// 营销商品
	} else if(Number(topType||'0')==9) {
		url += '&ppType=3';// 虚拟商品
	} else if(Number(topType||'0')==5) {
		url += '&ppType=2';// 配件
	} else {
		url += '&ppType=1';// 印品
	}
	
	$.post(url,function(ret){	
		if(ret && ret.length>0){
			var html = '';
			for(var n=0; n<ret.length; n++){
				var chk = (Number(ret[n].item_id||'0')>0)?"checked":"";
				html += '<div style="width:150px;float:left">'+
					'<input type="checkbox" '+chk+' id="ppId_'+ret[n].pp_id+'" name="ppInfo" value="'+ret[n].pp_id+'"/>'+
					ret[n].name+'</div>';
			}
			$('#ppContent').append(html);
		}
	});
	
	// show dlg
	$("#ppBtn").show();
	$('#ppDlg').window({
		title:'输出参数(套餐)设定',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	
	$('#ppDlg').window('move',{top:20,left:20});
	$('#ppDlg').window('open');
}
function updPp(){
	var pps = $("input[name='ppInfo']:checked").map(function(){
        	return $(this).val();
        }).get().join(',');
	
	var id = $("#ppItemId").val();
	
	var url = appPath+"/itbItemsWeb/updPpRelInfo.action";
	var data = {
		itemId: id,
		relPpIds: pps
	}
	$.post(url,data,function(ret){
		if(ret == 'ok'){
			$.messager.alert('提示信息','关联输出参数已更新！','info');
		}else{
			$.messager.alert('提示信息','更新失败','info');
		}
	});
}
function cancelPp(){
	$('#ppDlg').window('close');
}

/**
 * 获取请求信息(商品列表)
 */
function getQueryParam(){
	var queryObject = {};
	
	var findTypeL = $("#queryTypeL").combobox('getValue');
	var findTypeM = $("#queryTypeM").combobox('getValue');
	var findTypeS = $("#queryTypeS").combobox('getValue');
	var findState = $("#queryState").combobox('getValue');
	var findNo = $("#queryItemNo").val();
	var findName = $("#queryItemName").val();
	var findTmplId = $("#queryTmplId").val();
	var findItemId = $("#queryItemId").val();
	
	var findComIndx = $("#queryComIndex").combobox('getValue');
	
	if(findTypeL && Number(findTypeL||'0')>0) queryObject.findItemTypeL = findTypeL;// 大分类
	if(findTypeM && Number(findTypeM||'0')>0) queryObject.findItemTypeM = findTypeM;// 中分类
	if(findTypeS && Number(findTypeS||'0')>0) queryObject.findItemType = findTypeS;// 小分类
	if(findState && Number(findState||'0')>0) queryObject.findItemState = findState;// 状态
	if(findNo && findNo.length>0) queryObject.findItemNo = findNo;// 编号
	if(findName && findName.length>0) queryObject.findItemName = findName;// 名称
	if(findTmplId && Number(findTmplId||'0')>0) queryObject.findDesignId = findTmplId;// 模版id
	if(findItemId && Number(findItemId||'0')>0) queryObject.findItemId = findItemId;// 商品id
	if(findComIndx && Number(findComIndx)>=-1) queryObject.findComIndx = findComIndx;// 商品id
	
	return queryObject;
}

/**
 * 获取请求信息(模版列表)
 */
function getQueryParam2(){
	var queryObject = {
		findPubFlg: 1,
		itemIdForItems: Number($("#lnkItemId").val()||'0'),
		findTmplType: Number($("#lnkTypeS").val()||'0')
	};
	return queryObject;
}

/**
 * 查询数据
 */
function doQuery(startFlg){
	$("#itemsGrid").datagrid('unselectAll');
	if(startFlg==1){
		$("#itemsGrid").datagrid('load', getQueryParam());
	} else {
		$("#itemsGrid").datagrid('reload', getQueryParam());
	}
}

function fmtCreateTime(value, rowData, rowIndex){
	if(!value)return "";
	var s = new Date(value);
	return rowData.create_time=$.DateUtil.format(s,'yyyy/MM/dd hh:mm:ss');
}




//******************************** 上传图片   *******************************
var myDomain = 'http://7xogoq.com1.z0.glb.clouddn.com';
var ossDmain = "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/";
var validFile = false;
var uploader = null;
var uploader1 = null;


// 图像缩放
function DrawImage(ImgD,FitWidth,FitHeight){
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        if(image.width/image.height>= FitWidth/FitHeight){
            if(image.width>FitWidth){
                ImgD.width=FitWidth;
                ImgD.height=(image.height*FitWidth)/image.width;
            }else{
                ImgD.width=image.width; 
               ImgD.height=image.height;
            }
        } else{
            if(image.height>FitHeight){
                ImgD.height=FitHeight;
                ImgD.width=(image.width*FitHeight)/image.height;
            }else{
                ImgD.width=image.width; 
               ImgD.height=image.height;
            } 
       }
    }
}

function isImage(url) {
    var res, suffix = "";
    var imageSuffixes = ["png", "jpg", "jpeg", "gif", "bmp"];
    var suffixMatch = /\.([a-zA-Z0-9]+)(\?|\@|$)/;

    if (!url || !suffixMatch.test(url)) {
        return false;
    }
    res = suffixMatch.exec(url);
    suffix = res[1].toLowerCase();
    for (var i = 0, l = imageSuffixes.length; i < l; i++) {
        if (suffix === imageSuffixes[i]) {
            return true;
        }
    }
    return false;
}

function doPostData(){// 开始上传
	if (validFile && uploader) {
		uploader.start();
	} else {
		setMsg("red", "请选择图像文件！");
	}
}

function setMsg(color, msg) {
	$.messager.alert('提示信息',msg,'info');
}

function fmtCreateTime(value, rowData, rowIndex){
	if(!value)return "";
	var s = new Date(value);
	return rowData.create_time=$.DateUtil.format(s,'yyyy/MM/dd hh:mm:ss');
}

function fmtHotFlag(value, rowData, rowIndex){
	if(rowData.hotFlag==1)return "是";
	return "否";
}





// ############### FOR OSS UPLOAD START ###############
//var accessid= '';
//var accesskey= '';
//var uploadHost = 'http://itbour-back.oss-cn-hangzhou.aliyuncs.com';
var g_object_name = '';
var dtNow = Date.parse(new Date()); //Date.parse(new Date())/1000;
//var policyText = {
//"expiration": "2020-01-01T12:00:00.000Z", //设置该Policy的失效时间，超过这个失效时间之后，就没有办法通过这个policy上传文件了
//"conditions": [
//  ["content-length-range", 0, 104857600] // 设置上传文件的大小限制
//]
//};
//var policyJsonStr = JSON.stringify(policyText);
//var policyBase64 = Base64.encode(policyJsonStr);
//var message = policyBase64;
//var bytes = Crypto.HMAC(Crypto.SHA1, message, accesskey, { asBytes: true });
//var signature = Crypto.util.bytesToBase64(bytes);

var OSS_PARAM = {
	expire: 0,
	uploadHost: '',
	accessKeyId: '',
	policyBase64: '',
	signature: '',
	flg: false
};

function randomString(len) {
	len = len || 20;
	var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';   
	var maxLen = chars.length;
	var str = '';
	for (var i = 0; i < len; i++) {
		str += chars.charAt(Math.floor(Math.random() * maxLen));
    }
	return str;
}

function getSuffix(filename) {
    var pos = filename.lastIndexOf('.');
    var suffix = '';
    if (pos != -1) {
        suffix = filename.substring(pos);
    }
    return suffix;
}

function calculate_object_name(filename) {
	if (g_object_name){
		g_object_name = '';
	}
	var now = new Date(); 
	var nowStr = now.format("yyyy/MM/dd/hhmmssS_");
    g_object_name = "image/U"+g_userId+"/"+nowStr + randomString(20);
}

function set_upload_param(up, filename, ret) {
	// 判断当前expire是否超过了当前时间,如果超过了则重新取
	dtNow = Date.parse(new Date());//  Date.parse(new Date())/1000
	OSS_PARAM.flg = false;
    if (OSS_PARAM.expire < dtNow + 5000) {// 5s
    	var url = appPath+"/itbImg/getOSSToken.action";
        $.get(url, function(data){  
    		if (data && data.signature) { 
    			OSS_PARAM.expire = data.expire;
    			OSS_PARAM.uploadHost = data.uploadHost;
    			OSS_PARAM.accessKeyId = data.accessKeyId;
    			OSS_PARAM.policyBase64 = data.policyBase64;
    			OSS_PARAM.signature = data.signature;
    			OSS_PARAM.flg = true;
    			
    			doUpStart(up, filename, ret);
            } else {
            	$.messager.alert('提示信息','上传异常, 请重新尝试!','info');
            }  
        });
    } else {
    	doUpStart(up, filename, ret);
    }
}

function doUpStart(up, filename, ret){
	if (filename && filename != '') {
        calculate_object_name(filename);
    }
    var new_multipart_params = {
        'key' : g_object_name,
        'policy': OSS_PARAM.policyBase64,
        'OSSAccessKeyId': OSS_PARAM.accessKeyId, 
        'success_action_status' : '200', //让服务端返回200,不然，默认会返回204
        'signature': OSS_PARAM.signature,
    };

    up.setOption({
        'url': OSS_PARAM.uploadHost,
        'multipart_params': new_multipart_params
    });

    up.start();
}

function clearUploadList() {
}

function initOSS() {
	if (uploader) {
		uploader.destroy();
		uploader = null;
	}

	uploader = new plupload.Uploader({
		runtimes : 'html5,flash,silverlight,html4',
		browse_button : 'selImgFile2', 
	    //multi_selection: false,
		//container: document.getElementById('container'),
		//flash_swf_url : 'lib/plupload-2.1.2/js/Moxie.swf',
		//silverlight_xap_url : 'lib/plupload-2.1.2/js/Moxie.xap',
	    url : 'http://oss.aliyuncs.com',
		init: {
			PostInit: function() {// 当Init事件发生后触发
//				document.getElementById('upImgFile').onclick = function() {
//		            set_upload_param(uploader, '', false);
//		            return false;
//				};
			},

			FilesAdded: function(up, files) {
				var delLen = (up.files.length>=files.length)?(up.files.length-files.length):up.files.length;
				up.splice(0,delLen);
				
				var bAllOk = true;
				plupload.each(files, function(file) {
					if (isImage(file.name)) {
						// add file info list
						set_upload_param(uploader, '', false);
					} else {
						bAllOk = false;
						var ngFile = up.getFile(file.id);
						if (ngFile) {
							up.removeFile(ngFile);
						}
					}
				});
				
				if (!bAllOk) {
					setMsg("red", "已过滤非图像文件！");
				}     
			},

			BeforeUpload: function(up, file) {
	            set_upload_param(up, file.name, true);
	        },

			UploadProgress: function(up, file) {
//				var d = document.getElementById(file.id);
//				d.getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
//	            var prog = d.getElementsByTagName('div')[0];
//				var progBar = prog.getElementsByTagName('div')[0];
//				progBar.style.width= 2*file.percent+'px';
//				progBar.setAttribute('aria-valuenow', file.percent);
//				setMsg("green", file.name + ' 上传中...');
			},

			FileUploaded: function(up, file, info) {
	            if (info.status == 200) {
	            	console.log(g_object_name);
	            	var imgUrl = ossDmain+g_object_name
	            	if(imgUrl){
		        		delEditImg2(EDIT_IMG_IDX_2);// 只能有一张主图
		        		var showImg = imgUrl+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
		        		var imgHtml = '<div style="margin:20px;margin-top:30px;" id="editImg2_'+EDIT_IMG_IDX_2+'">'+
		        			'<a href="' + imgUrl + '" target="_blank" class="editImgUrl2" style="margin-right:10px;">'+
		        			'<img src="'+showImg+'" style="display:inline;">'+
		        			'</a>'+
		        			'<a href="javascript:void(0)" onclick="delEditImg2('+EDIT_IMG_IDX_2+')"">删除</a>'
		        			'</div>';
		        		$("#editItemThumb2").append(imgHtml);
		        	}
	            }
	            else {
	            	setMsg("red", '上传出错！');
	            }
			},

			Error: function(up, err) {
//				document.getElementById('console').appendChild(document.createTextNode("\nError xml:" + err.response));
				setMsg("red", err.response);
			}
		}
	});
	uploader.init();
}

function initOSS1() {
	if (uploader1) {
		uploader1.destroy();
		uploader1 = null;
	}

	uploader1 = new plupload.Uploader({
		runtimes : 'html5,flash,silverlight,html4',
		browse_button : 'selImgFile', 
	    //multi_selection: false,
		//container: document.getElementById('container'),
		//flash_swf_url : 'lib/plupload-2.1.2/js/Moxie.swf',
		//silverlight_xap_url : 'lib/plupload-2.1.2/js/Moxie.xap',
	    url : 'http://oss.aliyuncs.com',
		init: {
			PostInit: function() {// 当Init事件发生后触发
//				document.getElementById('upImgFile').onclick = function() {
//		            set_upload_param(uploader, '', false);
//		            return false;
//				};
			},

			FilesAdded: function(up, files) {
				var delLen = (up.files.length>=files.length)?(up.files.length-files.length):up.files.length;
				up.splice(0,delLen);
				
				var bAllOk = true;
				plupload.each(files, function(file) {
					if (isImage(file.name)) {
						// add file info list
						set_upload_param(uploader1, '', false);
					} else {
						bAllOk = false;
						var ngFile = up.getFile(file.id);
						if (ngFile) {
							up.removeFile(ngFile);
						}
					}
				});
				
				if (!bAllOk) {
					setMsg("red", "已过滤非图像文件！");
				}     
			},

			BeforeUpload: function(up, file) {
	            set_upload_param(up, file.name, true);
	        },

			UploadProgress: function(up, file) {
//				var d = document.getElementById(file.id);
//				d.getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
//	            var prog = d.getElementsByTagName('div')[0];
//				var progBar = prog.getElementsByTagName('div')[0];
//				progBar.style.width= 2*file.percent+'px';
//				progBar.setAttribute('aria-valuenow', file.percent);
//				setMsg("green", file.name + ' 上传中...');
			},

			FileUploaded: function(up, file, info) {
	            if (info.status == 200) {
	            	console.log(g_object_name);
	            	var imgUrl = ossDmain+g_object_name
	            	if(imgUrl){
	            		EDIT_IMG_IDX = Number(EDIT_IMG_IDX||0)+1;
	            		console.info("全局"+EDIT_IMG_IDX);
	            		$("#imgIdx").val(EDIT_IMG_IDX);
	            		var showImg = imgUrl+'?x-oss-process=image/resize,m_lfit,h_100,w_100';
	        			var imgHtml = '<div style="margin:20px;margin-top:30px;" id="editImg_'+EDIT_IMG_IDX+'">'+
	        				'<a href="' + imgUrl + '" target="_blank" id="editImg_a_'+EDIT_IMG_IDX+'" class="editImgUrl" style="margin-right:10px;">'+
	        				'<img id="editImg_a_img_'+EDIT_IMG_IDX+'" src="'+showImg+'" style="display:inline;">'+
	        				'</a>'+
	        				'<a href="javascript:void(0)" onclick="delEditImg('+EDIT_IMG_IDX+')">删除</a>'+
	        				'<a href="javascript:void(0)" style="margin-left:20px;" onclick="upImage('+EDIT_IMG_IDX+')"">上移</a>'+
	        				'</div>';
	        			$("#editItemThumb").append(imgHtml);
	            	}
	            }
	            else {
	            	setMsg("red", '不好意思上传出错,换张图图试试或者清除浏览器缓存！');
//	            	document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = info.response;
	            }
			},

			Error: function(up, err) {
//				document.getElementById('console').appendChild(document.createTextNode("\nError xml:" + err.response));
				setMsg("red", err.response);
			}
		}
	});
	uploader1.init();
}
//############### FOR OSS UPLOAD END ###############
